<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>Linux如何分大于2T的磁盘分区 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>Linux如何分大于2T的磁盘分区</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux/">Linux</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;之前一直没有接触过大于2T的磁盘分区的情况，只是听说Linux下大于2T的磁盘分区有问题。当自己遇到的时候，才真实体会到。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;使用fdisk 工具分区的时候，如果分大于2T的分区，会提示：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">Value out of range.</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;所以不能使用fdisk这个分区工具了，要是用parted 来进行分区。 </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;我们使用fdisk -l  查看磁盘的时候会发现一段警告：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="string">"WARNING: The size of this disk is 8.0 TB (7995995979776 bytes).</span></div><div class="line"><span class="string">DOS partition table format can not be used on drives for volumes</span></div><div class="line"><span class="string">larger than 2.2 TB (2199023255040 bytes). Use parted(1) and GUID</span></div><div class="line"><span class="string">partition table format (GPT)."</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这是因为我的/dev/sdb磁盘是8T，超过了2T. 超过2T只能将磁盘转化成GPT格式，GPT格式的磁盘相当于把原来MBR磁盘中原来保留4个分区表的4*16个字节只保留第一个16个字节，其它的类似于扩展分区，真正的分区表在512字节后，因此对GPT分区表来说是没有4个主分区的限制。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>MBR分区表（主引导）</strong>：</p>
<ul>
<li>支持的最大卷：2T(1T=1024GB)</li>
<li>对分区的限制：最多4个主分区或3个主分区和一个扩展分区</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>GPT分区表（GUID分区表）</strong>：</p>
<ul>
<li>支持最大卷：18EB（1EB=1024T）</li>
<li>对分区的限制：每个磁盘最多支持128个分区</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;好的，下面看看如何使用parted 来分区这个8T的磁盘？</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;我的打算是，sdb1 分一半也就是4T，sdb2分3T，sdb3分1T.</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line">parted /dev/sdb1</div><div class="line">GNU Parted 1.8.1</div><div class="line">使用 /dev/sdb1</div><div class="line">Welcome to GNU Parted! Type <span class="string">'help'</span> to view a list of commands.</div><div class="line">(parted) <span class="built_in">help</span></div><div class="line">check NUMBER                             <span class="keyword">do</span> a simple check on the file system</div><div class="line">  cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER   copy file system to another partition</div><div class="line">  <span class="built_in">help</span> [COMMAND]                           prints general <span class="built_in">help</span>, or <span class="built_in">help</span> on COMMAND</div><div class="line">  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)</div><div class="line">  mkfs NUMBER FS-TYPE                      make a FS-TYPE file system on partititon NUMBER</div><div class="line">  mkpart PART-TYPE [FS-TYPE] START END     make a partition</div><div class="line">  mkpartfs PART-TYPE FS-TYPE START END     make a partition with a file system</div><div class="line">  move NUMBER START END                    move partition NUMBER</div><div class="line">  name NUMBER NAME                         name partition NUMBER as NAME</div><div class="line">  <span class="built_in">print</span> [free|NUMBER|all]                  display the partition table, a partition, or all devices</div><div class="line">  quit                                     <span class="built_in">exit</span> program</div><div class="line">  rescue START END                         rescue a lost partition near START and END</div><div class="line">  resize NUMBER START END                  resize partition NUMBER and its file system</div><div class="line">  rm NUMBER                                delete partition NUMBER</div><div class="line">  select DEVICE                            choose the device to edit</div><div class="line">  <span class="built_in">set</span> NUMBER FLAG STATE                    change the FLAG on partition NUMBER</div><div class="line">  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER</div><div class="line">  unit UNIT                                <span class="built_in">set</span> the default unit to UNIT</div><div class="line">  version                                  displays the current version of GNU Parted and copyright information</div><div class="line">(parted)</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;可以先使用 “help” 命令获取帮助。常用命令有：</p>
<ul>
<li>mklabel GPT：建立磁盘标签</li>
<li>print ：如果没有任何分区，它查看磁盘可用空间，当分区后，它会打印出分区情况</li>
<li>primary 0%  n% ：创建主分区，n为要分的分区占整个磁盘的百分比.（mkpart extended创建扩展分区），例如我这里要分一个占一半（4T）的分区，则写 0% 50%, 然后继续分3T “mkpart primary 51%  90%”, 再分一个1T的 “mkpart primary 91%  100%”</li>
<li>quit  ：分区完后，直接quit即可，不像fdisk分区的时候，还需要保存一下，这个不用。</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;所以，我的命令为：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">(parted) mklabel GPT</div><div class="line">(parted) <span class="built_in">print</span></div><div class="line">(parted) mkpart primary 0%  50%</div><div class="line">(parted) mkpart primary 51%  90%</div><div class="line">(parted) mkpart primary 91%  100%</div><div class="line">(parted) quit</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;分区完了首先需要把让内核知道添加新分区了：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">partprobe</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后就该格式化了:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">mkfs.ext3 /dev/sdb1</div><div class="line">mkfs.ext3 /dev/sdb2</div><div class="line">mkfs.ext3 /dev/sdb3</div></pre></td></tr></table></figure>

	

	
		<span class="different-posts"><a href="/2017/10/12/1. Linux 基础/20. Linux如何分大于2T的磁盘分区/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
